namespace CollabApp.Application.Interfaces;

/// <summary>
/// Redis 服务接口
/// 提供Redis数据库操作的统一接口，支持Hash、List、Set、ZSet等数据结构
/// </summary>
public interface IRedisService
{
    // Hash操作
    Task<Dictionary<string, string>> GetHashAllAsync(string key);
    Task<bool> HashSetAsync(string key, string field, string value);
    Task<bool> HashDeleteAsync(string key, string field);
    Task<string?> HashGetAsync(string key, string field);
    Task SetHashMultipleAsync(string key, Dictionary<string, string> hash);
    Task SetHashAsync(string key, string field, string value);
    Task<bool> DeleteHashAsync(string key, string field);
    
    // List操作
    Task<List<string>> ListRangeAsync(string key, long start = 0, long stop = -1);
    Task<long> ListLeftPushAsync(string key, string value);
    Task<long> ListRightPushAsync(string key, string value);
    Task<string?> ListLeftPopAsync(string key);
    Task<string?> ListRightPopAsync(string key);
    Task<long> ListPushAsync(string key, string value);
    
    // Set操作
    Task<HashSet<string>> GetSetMembersAsync(string key);
    Task<bool> SetAddAsync(string key, string value);
    Task<bool> SetRemoveAsync(string key, string value);
    Task<bool> SetContainsAsync(string key, string value);
    Task<long> GetSetCardinalityAsync(string key);
    
    // String操作
    Task<bool> StringSetAsync(string key, string value, TimeSpan? expiry = null);
    Task<string?> StringGetAsync(string key);
    Task<string?> GetStringAsync(string key);
    Task<bool> KeyDeleteAsync(string key);
    Task<bool> KeyExistsAsync(string key);
    Task<bool> ExistsAsync(string key);
    Task<bool> SetStringAsync(string key, string value, TimeSpan? expiry = null);
    
    // 过期时间
    Task<bool> KeyExpireAsync(string key, TimeSpan expiry);
    Task<bool> SetExpireAsync(string key, TimeSpan expiry);
    Task<bool> ExpireAsync(string key, TimeSpan expiry);
    
    // 泛型操作
    Task<T?> GetAsync<T>(string key) where T : class;
    Task<bool> SetAsync<T>(string key, T value, TimeSpan? expiry = null) where T : class;
    // ZSet操作
    Task<bool> SortedSetAddAsync(string key, string member, double score);
    Task<List<(string member, double score)>> SortedSetRangeByRankWithScoresAsync(string key, long start, long stop, bool descending = true);
    Task<double?> SortedSetScoreAsync(string key, string member);
    Task<long?> SortedSetRankAsync(string key, string member, bool descending = true);
    Task<bool> SortedSetRemoveAsync(string key, string member);
}